package top.fangw.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.fangw.admin.pojo.dto.SysOrgQueryDto;
import top.fangw.admin.pojo.entity.SysOrgInfo;
import top.fangw.admin.service.ISysOrgInfoService;
import top.fangw.common.api.vo.InitOrgVo;
import top.fangw.common.core.result.Result;

import java.util.List;

/**
 * <p>
 * 用途：存储机构信息 前端控制器
 * </p>
 *
 * @author fangw
 * @since 2024-03-02
 */
@Tag(name= "机构信息管理", description = "机构信息管理接口")
@RestController
@RequestMapping("/sys-org-info")
@RequiredArgsConstructor
public class SysOrgInfoController {

    private final ISysOrgInfoService sysOrgInfoService;

    @Operation(summary = "初始化租户机构信息--远程调用")
    @PostMapping("/initTenantOrg")
    public Result<InitOrgVo> initTenantOrg(@RequestBody InitOrgVo initOrgVo){
        return Result.success(sysOrgInfoService.initTenantOrg(initOrgVo));
    }

    @Operation(summary = "添加机构信息")
    @PostMapping("/add")
    public Result<?> add(@RequestBody SysOrgInfo sysOrgInfo){
        sysOrgInfoService.add(sysOrgInfo);
        return Result.success();
    }

    @Operation(summary = "分页获取机构树")
    @PostMapping("/pageList")
    public Result<?> pageList(@RequestBody SysOrgQueryDto sysOrgQueryDto){
        IPage<SysOrgInfo> res = sysOrgInfoService.pageList(sysOrgQueryDto);
        return Result.success(res);
    }

    @Operation(summary = "获取机构信息列表")
    @GetMapping("/queryList")
    public Result<?> queryList(){
        List<SysOrgInfo> res = sysOrgInfoService.queryList();
        return Result.success(res);
    }

    @Operation(summary = "删除机构信息")
    @GetMapping("/delete")
    public Result<?> delete(@RequestParam String id){
        sysOrgInfoService.delete(id);
        return Result.success();
    }

}
